package com.api.oa.controller;


import com.api.oa.model.entity.YQFace;
import com.api.oa.model.params.YQFaceParam;
import com.api.oa.services.YQFaceService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yq/yQFace")
public class YQFaceController extends BaseController {

    @Autowired
    private YQFaceService iYQFaceService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public MyResult Add(@RequestBody YQFace entity) {
        try {
            return iYQFaceService.add(entity) == 1 ? success(entity) : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }

    @RequestMapping(value = "/remove/{id}", method = RequestMethod.POST)
    public MyResult remove(@PathVariable Long id) {
        try {
            iYQFaceService.remove(id);
            return success("删除成功!");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public MyResult update(@RequestBody YQFace entity) {
        try {
            return iYQFaceService.update(entity) == 1 ? success("操作成功") : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }

    @RequestMapping(value = "/reg", method = RequestMethod.POST)
    public MyResult reg(@RequestBody YQFaceParam entity) {
        try {
            return iYQFaceService.reg(entity) == 1 ? success("操作成功") : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MyResult list(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "20") Integer pageSize, @RequestParam(required = false) String insCode,
                         @RequestParam(required = false) String keyWord, @RequestParam(required = false) String role) {
        try {
            return success(iYQFaceService.list(insCode,keyWord, role,pageIndex, pageSize));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/unReg", method = RequestMethod.GET)
    public MyResult unReg(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "20") Integer pageSize,
                          @RequestParam(required = false) Long userId, @RequestParam(defaultValue = "0") String attendType,@RequestParam(required = false) String keyWord) {
        try {
            return success(iYQFaceService.patientFace(userId,attendType, keyWord,pageIndex, pageSize));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
    public MyResult one(@PathVariable Long id) {
        try {
            return success(id == null ? null : iYQFaceService.one(id));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/verify/{id}", method = RequestMethod.GET)
    public MyResult verify(@PathVariable Long id) {
        try {
            return success(id == null ? null : iYQFaceService.verify(id));
        } catch (Exception e) {
            return anomalous(e.getMessage());
        }
    }


    @RequestMapping(value = "/verify/tencent/{id}", method = RequestMethod.GET)
    public MyResult verifyTencent(@PathVariable Long id) {
        try {
            return success(id == null ? null : iYQFaceService.verifyTencent(id));
        } catch (Exception e) {
            return anomalous(e.getMessage());
        }
    }

}
